<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>发起请求</button>
    <h1 id="app" style="display:none">我是正确后的界面</h1>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./Promise封装请求方式.js"></script>

    <!-- 课堂练习 -->
    <script>
        const btn = document.querySelector('button')
        const app = document.getElementById('app')
        console.log(app);
        // btn.addEventListener('click', async function () {
        //     // console.log(1);
        //     const res = await harryAjax({
        //         method: 'GET',
        //         url: 'http://ajax-base-api-t.itheima.net/api/getbooks'
        //     })
        //     console.log(res);
        //     const { data } = res
        //     // console.log(data);
        // })

        // 作业内容：
        Promise.all([
            // 正确请求
            myAjax({
                method: 'GET',
                url: 'http://ajax-base-api-t.itheima.net/api/getbooks'
            }),
            //  错误请求
            // myAjax({
            //     method: 'POST',
            //     data: { bookname: '蔡徐坤的黑子练成计', author: '鸡哥', publisher: '蔡徐坤出版社' },
            //     url: 'http://ajax-base-api-t.itheima.net/api/addbooks'
            // })
        ]).then(res => {
            console.log(res);
            app.style.display = 'block'
        }).catch(err => {
            console.log(err);
            app.style.display = 'block'
            app.innerHTML = `你获取错了沙雕,这个${err}是什么鬼`
        })
    </script>
</body>

</html>